package module.map.nodes
{
	import drongo.model.events.ModelEvent;
	
	import flash.filesystem.File;
	
	import module.map.model.Propertys;
	
	import ui.Map.UI_ImageNodeView;
	
	public class ImageNodeMediator extends BaseNodeMediator
	{
		[Inject]
		public var view:UI_ImageNodeView;
		
		public function ImageNodeMediator()
		{
			super();
		}
		
		override public function destroy():void
		{
			super.destroy();
			this.RemoveEvents();
			this.nodes=null;
			this.nodeData=null;
			this.stage=null;
			this.project=null;
		}
		
		override public function initialize():void
		{
			super.initialize();
			this.Init(this.view);
			this.RefreshView();
		}
		
		private function RefreshView():void{
			this.view.x=this.nodeData.Get(Propertys.X).GetValue();
			this.view.y=this.nodeData.Get(Propertys.Y).GetValue();
			this.view.visible=this.nodeData.Get(Propertys.VISIBLE).GetValue()==1;
			this.view.touchable=this.nodeData.Get(Propertys.LOCK).GetValue()==0;
			
			var imagePath:String=this.project.imagesFile.nativePath+File.separator+nodeData.Get(Propertys.PATH).GetValue();
			this.view.m_image.url=imagePath;
		}
		
		override protected function AddEvents():void{
			super.AddEvents();
			this.nodeData.addEventListener(ModelEvent.CHILD_VALUE_CHANGED,this.PropertyUpdateHandler);
		}
		
		override protected function RemoveEvents():void{
			super.RemoveEvents();
			this.nodeData.removeEventListener(ModelEvent.CHILD_VALUE_CHANGED,this.PropertyUpdateHandler);
		}
		
		private function PropertyUpdateHandler(e:ModelEvent):void{
			this.RefreshView();
		}
	}
}